<%--
  Created by IntelliJ IDEA.
  User: lucongyue
  Date: 2017/12/5
  Time: 14:27
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<h1>消息列表</h1>
<div class="" id="conHeight">
    <div class="tab-content newContent">
        <p>数据总量：${pageInfo.total}条</p>
        <div class="search-form">
            <div class="form-inline">
                <div class="form-group">
                    <label>所属app：</label>
                    <select id="appId" class="form-control" value="${appId}" onchange="changeApp()">
                        <c:forEach var="appInfo" items="${appInfoList}">
                            <option value="${appInfo.appId}"
                                    <c:if test="${appInfo.appId eq appId}">selected</c:if>   >${appInfo.name}</option>
                        </c:forEach>
                    </select>

                    <label>用户名称：</label>
                    <select id="userName" class="form-control" value="${userName}" onchange="changeUser()"
                            style="max-width: 400px;">
                        <c:forEach var="name" items="${userList}">
                            <option value="${name}"
                                    <c:if test="${userName eq name}">selected</c:if>   >${name}</option>
                        </c:forEach>
                    </select>
                </div>
            </div>
        </div>
        <div class="tab-pane active" id="configuration">
            <div>
                <div class="no">
                    <table class=" data-table table table-striped table-responsive text-center"
                           style="word-break:break-all; word-wrap:break-word;">
                        <thead>
                        <tr>
                            <th width="5%">序号</th>
                            <th width="7%">发送方</th>
                            <th width="7%">接收方</th>
                            <th width="8%">消息类型</th>
                            <th width="8%">消息格式</th>
                            <th width="30%">消息内容</th>
                            <th width="10%">消息状态</th>
                            <th width="15%">时间</th>
                            <th width="10%">操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        <c:forEach items="${pageInfo.list}" var="message" varStatus="status">
                            <tr>
                                <td>${pageInfo.startRow+status.index}</td>
                                <td>${message.from}</td>
                                <td>${message.to}</td>
                                <td>
                                    <c:if test="${100==message.code||105==message.code}">普通消息</c:if>
                                    <c:if test="${106==message.code}">自动回复消息</c:if>
                                    <c:if test="${101==message.code || 102==message.code || 103==message.code || 104==message.code}">系统消息</c:if>
                                    <c:if test="${200==message.code }">心跳消息</c:if>
                                    <c:if test="${300==message.code ||301==message.code}">错误消息</c:if>
                                    <c:if test="${400==message.code }">重新登录消息</c:if>
                                </td>
                                <td>${message.type}</td>
                                <td>${message.text}</td>
                                <td>
                                    <c:if test="${0==message.status}">未发送</c:if>
                                    <c:if test="${0!=message.status}">已发送</c:if>
                                </td>
                                <td>
                                    <fmt:formatDate value="${message.time}"
                                                    pattern="yyyy-MM-dd HH:mm:ss"></fmt:formatDate>
                                </td>
                                <td>
                                    操作
                                </td>
                            </tr>
                        </c:forEach>
                        </tbody>
                    </table>


                </div>

            </div>
        </div>
        <!--分页开始-->
        <div class="page">
            <c:if test="${pageInfo.total > 10 }">
                <ul class="pageMenu clearfix">
                    <c:if test="${pageInfo.hasPreviousPage}">
                        <li onclick="conditionPageQuery(${pageInfo.prePage});"><a href="#"
                                                                                             aria-label="Previous">
                            &lt;上一页 </a></li>
                    </c:if>
                    <c:forEach items="${pageInfo.navigatepageNums}" var="curretPageNum" varStatus="status">
                        <c:choose>
                            <c:when test="${curretPageNum==pageInfo.pageNum}">
                                <li class="disabled"><a href="#">${curretPageNum}</a></li>
                            </c:when>
                            <c:otherwise>
                                <li onclick="conditionPageQuery(${curretPageNum});"><a href="#"
                                >${curretPageNum}</a>
                                </li>
                            </c:otherwise>
                        </c:choose>
                    </c:forEach>
                    <c:if test="${pageInfo.hasNextPage}">
                        <li onclick="conditionPageQuery(${pageInfo.nextPage});"><a href="#"
                                                                                              label="Next">
                            下一页&gt; </a></li>
                    </c:if>
                    <li class="last" style="font-size: 14px;">
                        共<span class="totalPage">${pageInfo.pages}</span>页，跳转至 <input type="number"
                                                                                      onkeyup='this.value=this.value.replace(/\D/gi,"")'
                                                                                      class="keuInput"
                                                                                      value="${pageInfo.pageNum}"
                                                                                      id="pageTogo"/>
                        <input type="button" class="btnSure" value="确定" onclick="pageSizeGo();" class="turnTo"/>
                    </li>
                </ul>
            </c:if>
        </div>
    </div>

</div>


<script>

    var appId = "${appId}";
    var userName = "${userName}";

    function changeApp() {
        appId = $("#appId").val();
        userName = null;
        conditionPageQuery(1);
    }

    function changeUser() {
        userName = $("#userName").val();
        conditionPageQuery(1);
    }

    function conditionPageQuery(currentPageNum) {
        var data = {
            "page": currentPageNum,
            "appId": appId,
            "userName": userName,
        };
        $("#rightMainContent").load("index/message", data);
    }

    function pageSizeGo() {
        var page = parseInt($("#pageTogo").val());
        var no = 1;
        var currentpage = parseInt("${pageInfo.pageNum }");
        var totalPage = parseInt("${pageInfo.pages }");

        if (currentpage == page) {

        }
        else if (0 < page && page < totalPage + 1) {
            conditionPageQuery(page);
        }
        else {
            /*$.messager.show({
                title: "提示信息",
                msg: "输入页数超出范围!"
            });*/
            alert("输入页数超出范围");
        }
    }
</script>
